package com.jishuo.nontax.bfc.ca;

import cn.com.jit.assp.css.client.CSSException;
import cn.com.jit.assp.css.client.Config;
import cn.com.jit.assp.css.client.DSignClient;
import cn.com.jit.assp.css.client.ResultSet;
import cn.com.jit.assp.css.client.util.UtilTool;

public class JitDSign {
    private static Config config = null;
    private static boolean IS_INITED = false;
    private long longErrCode = 0L;
    private String strErrMsg = null;
    private ResultSet rs = null;
    private DSignClient dsclient = null;
    private byte[] plainByteData;
    private String plainData = "";

    public JitDSign() {
        this.dsclient = new DSignClient();
        config = Config.getInstance();
        this.rs = new ResultSet();
    }

    public static boolean init(String filePath) {
        if (IS_INITED) return true;
        synchronized(JitDSign.class) {
            if (!IS_INITED) {
                try {
                    if (config == null) {
                        config = Config.getInstance();
                    }

                    config.loadConfig(filePath, false);
                } catch (CSSException var3) {
                    return false;
                }

                IS_INITED = true;
            }
        }

        return true;
    }

    public long decryptEnvelop(byte[] bEnvelop) {
        this.longErrCode = 0L;
        this.strErrMsg = null;
        long lRtnValue = 0L;
        this.rs.clear();

        try {
            this.rs = this.dsclient.unEnvelop(bEnvelop);
            if (!this.rs.isSucceed()) {
                lRtnValue = UtilTool.convertStr2Long(this.rs.getErrcode(), 10700000L);
                this.longErrCode = lRtnValue;
                this.strErrMsg = this.rs.getErrDisc();
            } else {
                this.plainByteData = this.rs.getPlainData();
                String fileName = this.rs.getFileName();
                if (fileName.equals("")) {
                    this.plainData = new String(this.plainByteData);
                } else {

                }
            }

            return lRtnValue;
        } catch (CSSException var5) {
            this.longErrCode = UtilTool.convertStr2Long(var5.getCode(), 10700000L);
            this.strErrMsg = var5.getDescription();
            return this.longErrCode;
        }
    }

    public byte[] getPlainByteData() {
        return plainByteData;
    }

    public String getPlainData() {
        return plainData;
    }

    public long getErrorCode() {
        return longErrCode;
    }

    public String getErrorMessage() {
        return strErrMsg;
    }
}
